<template>
    <el-dialog v-if="dialogVisible" :close-on-click-modal='false' title="关联人" :visible.sync="dialogVisible" @close="resetForm('addForm')" width="400px">
        <el-form label-position="top" :model="addForm" :hide-required-asterisk='true' ref="addForm" :rules="addRules" class="dialog_form">
            <el-form-item label="小店随心推关联人" prop="user_id" style="margin-bottom:0">
                <el-select v-model="addForm.user_id" placeholder="请选择小店随心推关联人" filterable style="width:100%">
                    <el-option :label="item.nickname" :value="item.id" v-for="item in relateList" :key="item.id"></el-option>
                </el-select>
            </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
            <el-button size="small" @click="resetForm('addForm')" class="el-button-width">取 消</el-button>
            <el-button size="small" type="primary" @click="submitForm('addForm')" :disabled="loading" :loading="loading" class="el-button-width">确 认</el-button>
        </span>
    </el-dialog>
</template>

<script>
export default {
    name: "",
    data() {
        return {
            loading: false,
            dialogVisible: false,
            relateList:[],
            addForm: {
                advertiser_id: "",
                is_follow: "",
                user_id:''
            },
            addRules: {
                user_id: [
                    {
                        required: true,
                        message: "请选择小店随心推关联人",
                        trigger: ["blur", "change"],
                    },
                ],
            },
        };
    },
    created() {
        
    },
    methods: {
        //获取关联人列表
        async getBrandList() {
            const { data: res } = await this.$http.post(
                "/adminapi/company/hzOptimizerList"
            );
            if (res.code !== 200) {
                this.$message.error(res.msg);
                return;
            } else {
                this.relateList = res.data;
            }
        },


        // 提交添加
        submitForm(formName) {
            this.$refs[formName].validate(async (valid) => {
                if (valid) {
                    this.loading = true;
                    const { data: res } = await this.$http.post(
                        "qcadmin/Qcaccount/follow",
                        this.addForm
                    );
                    if (res.code !== 200) {
                        this.$message.error(res.msg);
                        this.loading = false;
                        return;
                    } else {
                        this.$message({
                            message: "保存成功",
                            type: "success",
                        });
                        this.loading = false;
                        this.$emit("getDataList",1)
                        this.resetForm(formName);
                    }
                } else {
                    this.loading = false;
                    return false;
                }
            });
        },

        // 关闭重置表单
        resetForm(formName) {
            this.dialogVisible = false;
            this.$refs[formName].resetFields();
        },
    },
    components: {},
};
</script>


<style scoped>
</style>
